package py.com.fms.converter;

import java.io.Serializable;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.log.Log;

import py.com.fms.exception.CommonException;
import py.com.fms.fms.bean.VoucherBean;
import py.com.fms.fms.persistence.services.PersonServices;
import py.com.fms.session.ServiceSqlMap;
import py.com.fms.session.WithinHolder;

@SuppressWarnings("unused")
@Name("voucherConverter")
public class VoucherConverter implements Serializable, Converter {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6104756219006168962L;
	@Logger
	private Log log;
	@In("#{serviceSqlMap}")
	private ServiceSqlMap sqlMap;

	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		// TODO Auto-generated method stub
		if (arg2 != null) {
			try {
				WithinHolder aid = (WithinHolder)Component.getInstance(WithinHolder.class, true);
				if (aid == null) {
					return null;
				}
				VoucherBean bean = aid.voucherData(arg2);
				return bean;

			} catch (ConverterException e) {
				this.log.error(e);
			}
		}
		return null;
	}

	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		// TODO Auto-generated method stub
		if (arg2 instanceof VoucherBean) {
			VoucherBean bean = (VoucherBean) arg2;
			return bean.getAbrev();

		}
		return null;
	}

}
